<?php

class model_wishBalance extends L {

    /**
     * 描述 ：分页的查询语句拼接
     * 作者 ：Zoro.Zhu
    **/
    public static function searchSql($params = array()){
        $sql = "SELECT
             `id`, `account`, `date`, `type`, `data`
        FROM
            `wish_balance`
        WHERE 1";
        $dxmAccount = model_com::getAccount('wish');
        $sql .= " AND `account` IN ('" . join("','", $dxmAccount) . "')";
        $sql .= !empty($params['search']['account']) ? "AND `account` IN ('" . join("','", $params['search']['account']) . "') " : "";
        $sql .= !empty($params['search']['dateStart']) ? " AND `date` >= '{$params['search']['dateStart']}' " : "";
        $sql .= !empty($params['search']['dateEnd']) ? " AND `date` <= '{$params['search']['dateEnd']}' " : "";
        $sql .= !empty($params['search']['type']) ? "AND `type` IN ('" . join("','", $params['search']['type']) . "') " : "";
        return $sql;
    }

    /**
     * 描述 ：执行修改数据的sql
     * 作者 ：Zoro.Zhu
    **/
    public static function updateSql($data = array()){
        $sql = "UPDATE `wish_balance` 
        SET 
            `account` = '{$data['account']}',
            `date` = '{$data['date']}',
            `type` = '{$data['type']}',
            `data` = '{$data['data']}'
        WHERE
            `id` = '{$data['id']}'";
        return L::sql($sql);
    }

    /**
     * 描述 ：执行插入数据的sql
     * 作者 ：Zoro.Zhu
    **/
    public static function insertSql($data = array()){
        $sql = "INSERT INTO `wish_balance`(
             `account`, `date`, `type`, `data`
        ) VALUES (
             '{$data['account']}', '{$data['date']}', '{$data['type']}', '{$data['data']}'
        )";
        return L::sql($sql);
    }

    /**
     * 描述：根据主键获取数据
     * 作者：Zoro.Zhu
    **/
    public static function getKeyInfo($key){
        $sql = "SELECT
             `id`, `account`, `date`, `type`, `data`
        FROM
            `wish_balance`
        WHERE 
            `id` = '{$key}'";
        return L::sql($sql);
    }

}